<?php
/**
 * Created by PhpStorm.
 * User: C。
 * Date: 2019/8/13
 * Time: 9:04
 */
namespace app\home\controller;

use app\common\model\JingshuWord as JingshuWordModel;

/**
 * 经书文字控制器
 * Class Jingshuword
 * @package app\home\controller
 */
class Jingshuword extends Base
{
    /**
     * [index 获取文字列表]
     * @param
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new JingshuWordModel;
        try{
            $data = $model->getAllData(['pid'=>$param['pid']],'sort','id,img,pid','asc');
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '失败'.$e->getMessage());
        }
        return admin_json(1, '成功',$data);
    }
    /**
     * [get 获取单个文字图]
     * @param
     * @return json
     * @author [C。]
     */
    public function get()
    {
        $param = input('param.');
        $model = new JingshuWordModel;
        try{
            $data = $model->findOne(['pid'=>$param['pid'],'sort'=>$param['number']],'id,img,word');
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '失败'.$e->getMessage());
        }
        return admin_json(1, '成功',$data);
    }
    /**
     * [get 获取单个文字图]
     * @param
     * @return json
     * @author [C。]
     */
    public function edit()
    {
        $param = input('param.');
        $model = new JingshuWordModel;
        try{
            $word = $model->findData($param['id'],'id','img');
            $result = substr($word['img'],strripos($word['img'],"jingshu"));
            ossdel($result);
            $model->editData(['id'=>$param['id'],'img'=>$param['img']]);
        }catch(\Exception $e){
            systembug($e->getMessage(),2,$this->url);
            return admin_json(-1, '失败'.$e->getMessage());
        }
        return admin_json(1, '成功');
    }
}